#!/bin/sh

printf "Domain root: "
read -r domain_root
printf "Subdomain (can be empty): "
read -r sub_domain
printf "Use certificate signed by Let's Encrypt (Y/n): "
read -r signed

[ "${signed}" = "${signed#[Yy]}" ]
signed=$?

if [ $signed -ne 0 ]; then
    printf "Email: "
    read -r email
fi

if [ -z "$sub_domain" ]
then
  domain="${domain_root}"
else
  domain="${sub_domain}.${domain_root}"
fi

mkdir -p ./docker/bootstrap

cat > ./docker/bootstrap/bootstrap.env <<EOF
#!/bin/sh
email=${email}
domain=${domain}
domain_root=${domain_root}
signed=${signed}
EOF

chmod +x ./docker/bootstrap/bootstrap.env

docker-compose -f docker/bootstrap/bootstrap.yaml up
